package com.yc.chaoshi.cs_manage.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.chaoshi.cs_manage.mapper.UmsResourceMapper;
import com.yc.chaoshi.cs_manage.service.IUmsResourceService;
import com.yc.chaoshi.entity.UmsResource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xz
 * @since 2022-08-04
 */
@Service
public class UmsResourceServiceImpl extends ServiceImpl<UmsResourceMapper, UmsResource> implements IUmsResourceService {


    @Override
    public Page listAll(Integer pageNum, Integer pageSize, String sreachname, String sreachurl) {
        Page<UmsResource> page=new Page<>(pageNum,pageSize);
        pageNum=pageSize*(pageNum-1);
        List<UmsResource> list=this.baseMapper.listAll(pageNum,pageSize,sreachname,sreachurl);
        long total=this.baseMapper.listAll(0,10000,sreachname,sreachurl).size();
        page.setRecords(list);
        page.setTotal(total);
        return page;
    }

    @Override
    public Boolean add(UmsResource umsRoles) {
        umsRoles.setCreateTime(LocalDateTime.now());
        boolean result=this.save(umsRoles);
        if (result){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean edit(UmsResource umsRoles) {
        if (this.updateById(umsRoles)){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<UmsResource> listByid(Integer roleid) {
        return this.baseMapper.listByid(roleid);
    }

    @Override
    public Page listResource(Integer pageNum, Integer pageSize, String sreachname, String sreachurl, Integer roleid) {
        Page<UmsResource> page=new Page<>(pageNum,pageSize);
        pageNum=pageSize*(pageNum-1);
        List<UmsResource> list=this.baseMapper.listResource(pageNum,pageSize,sreachname,sreachurl,roleid);
        long total=this.baseMapper.listResource(0,10000,sreachname,sreachurl,roleid).size();
        page.setRecords(list);
        page.setTotal(total);
        return page;
    }

}
